<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电信管理系统</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="assets/element-plus/index.css">
    <!-- 引入组件库 -->
    <script src="/assets/vue/vue.global.js"></script>
    <script src="/assets/element-plus/index.full.js"></script>
    <script src="/assets/axios/axios.js"></script>
    <script src="/assets/oa/security.js"></script>
    <style>
        .el-header {
            background-color: rgb(238, 241, 246);
            color: #333;
            line-height: 60px;
        }
        html,body,#app,.el-container {
            padding: 0px;
            margin: 0px;
            height: 100%;
            max-height: 100%;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container style="height:100%;border:1px solid #eee">
        <el-header>
            <el-row>
                <el-col :span="12">
                    <span style="font-size: 18px;color:darkcyan">电信管理系统</span>
                </el-col>
                <el-col :span="12" style="text-align:right">
                    <el-dropdown>
                        <i class="el-icon-s-check" style="font-size:18px;margin-right: 15px; display: flex; align-items: center;">
                            <span style="margin-right: 5px;">[{{managername}}]</span>
                            <img :src="getImageUrl(avatarUrl)" alt="Avatar" style="width: 58px; height: 58px; border-radius: 50%;margin-right: 15px;">
                        </i>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item v-on:click="logout">退出</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </el-col>
            </el-row>
        </el-header>
        <el-container>
            <el-aside width="200px" style="max-height:100%;background-color: rgb(238, 241, 246)">
                <!--默认展开第一个模块功能-->
                <el-menu :default-openeds="['0']">
                    <template v-for="(n,idx) in nodeList">
                        <el-submenu :index="idx.toString()">
                            <template #title><i class="el-icon-s-tools"></i>{{n.node.name}}</template>
                            <template v-for="func in n.children">
                                <el-menu-item :index="func.permissionId.toString()" v-on:click="showPage(func.url)">{{func.name}}</el-menu-item>
                            </template>
                        </el-submenu>
                    </template>
                </el-menu>
            </el-aside>
            <el-main>
                <iframe id="main" name="main" src="/notice.html" style="width:100%;height:95%;border: 0px"></iframe>
            </el-main>
        </el-container>
    </el-container>
</div>
<script>
    const Main = {
        data(){
            return {
                nodeList:[],
                managername:"",
                avatarUrl: "" // Add avatarUrl in data
            }
        },
        methods:{
            showPage(url){
                document.getElementById("main").src = url;
            },
            logout(){
                sessionStorage.clear();
                window.location.href = "/login.html";
            }
            ,getImageUrl(profilepicture) {
                // 假设后端图片存储在 /imgs 目录下
                return `/images/${profilepicture}`;
            }
        },
        mounted(){
            const objApp = this;
            const managerid = sessionStorage.managerid;
            const managername=sessionStorage.managername;
            const profilepicture=sessionStorage.profilepicture;
            objApp.managername=managername;

            // Fetch user info including avatar URL
            axios.get("/managerinfo/managerinfo?uid=" + managerid)
                .then(function(response){
                    const json = response.data;
                    json.data.nodeList.forEach(function (item){
                        objApp.nodeList.push(item);
                    });

                    // Set avatar URL
                    objApp.avatarUrl = profilepicture;
                });
        }
    };
    const app = Vue.createApp(Main);
    app.use(ElementPlus);
    app.mount("#app");
</script>
</body>
</html>
